package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.PhoneBookService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @描述 小程序通讯录（教师端）
 * @创建人 zm
 * @创建时间 2020/4/27
 */
@RestController
@RequestMapping("/jurisdiction")
public class PhoneBookController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private PhoneBookService service;

    /**
     * @描述 教师通讯录（教师端）
     * @创建人 zm
     * @创建时间 2020/4/27
     */
    @RequestMapping("/queryTeacherPhoneBook")
    public Result queryTeacherPhoneBook(RequestParameterWrapper request) {

        logger.info("查询教师通讯录 PhoneBookController -> queryTeacherPhoneBook");
        //获取学校id
        String schoolId = request.getParam("schoolId");
        String teacherId = request.getParam("teacherId");
        return service.queryTeacherPhoneBook(schoolId, teacherId);
    }

    /**
     * @描述 添加/取消被关注的人
     * @创建人 zm
     * @创建时间 2020/5/20
     */
    @RequestMapping("/updateTeacherPhoneBook")
    public Result updateTeacherPhoneBook(RequestParameterWrapper request,
                                         @RequestParam(value = "id") String id,
                                         @RequestParam(value = "state") Integer state) {//被关注人的教师id

        logger.info("添加/取消被关注的人 PhoneBookController -> updateTeacherPhoneBook");
        //获取学校id
        String teacherId = request.getParam("teacherId");
        return service.updateTeacherPhoneBook(id,teacherId, state);
    }


    /**
     * @描述 查询家长通讯录
     * @创建人 zm
     * @创建时间 2020/4/27
     */
    @RequestMapping("/queryParentPhoneBook")
    public Result queryParentPhoneBook(RequestParameterWrapper request,
                                       @RequestParam(value = "classId", required = false) Integer classId,
                                       @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                       @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {

        logger.info("查询家长通讯录 PhoneBookController -> queryParentPhoneBook");
        //获取学校id
        String schoolId = request.getParam("schoolId");

        return service.queryParentPhoneBook(schoolId, classId, indexNo, rows);
    }


    /**
     * @描述 教师通讯录 （家长端）
     * @创建人 zm
     * @创建时间 2020/4/27
     */
    @RequestMapping("/queryTeacherPhoneBookBystudentId")
    public Result queryTeacherPhoneBookBystudentId(@RequestParam(value = "studentId") Integer studentId) {

        logger.info("教师通讯录 （家长端） PhoneBookController -> queryTeacherPhoneBookBystudentId");

        return service.queryTeacherPhoneBookBystudentId(studentId);
    }

}
